#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
int n;
long long arr[maxn];
int asdn[maxn];

int main() {
	// freopen("lis.in", "r", stdin);
	// freopen("lis.out", "w", stdout);
	cin >> n;
	for (int i = 1; i<= n; i++) cin >> arr[i];
	
	memset(asdn, 0, sizeof(asdn));
	for (int i=2; i<=n; i++) {
		int len = 1;
		for (int j=1; j<i; j++) {
			if (arr[j] < arr[i]) {
				len = max(len, asdn[j] + 1);
			} else {
				len = max(len, asdn[j]-1);
			}
 		}
 		asdn[i] = len;
	}
	cout << asdn[n] << endl;
	return 0;
} 
